<?php
class LexHelper extends AppHelper {
	public $helpers = array ('Html','Javascript','Session');

	function beforeRender(){
		parent::beforeRender();
		$this->View =& ClassRegistry::getObject('view');
	
		App::import('Component','Lex');
		$this->Lex = new LexComponent();
	}
	
	function __construct(){
		parent::__construct();

	}
	
	function offers_homepage(){
		$offers = array();
		$fields = array('id','lokalizacja','miasto','dzielnica','ulica','cena_od','powierzchnia_od','image','promocja','typ_name','transakcja_name');
		
		$offers = $this->Lex->get(array('conditions'=>array('ViewOffer.typ_id'=>array(0,1,2,3), 'ViewOffer.promocja'=>array(1,3)),'fields'=>$fields,'limit'=>3));
		if(empty($offers)) $offers = $this->Lex->get(array('conditions'=>array('ViewOffer.typ_id'=>array(0,1,2,3) ),'fields'=>$fields,'limit'=>3));
		


// 		debug($offers); 
		return $this->View->element('offer_icon_home',array('plugin'=>false,'offers'=>$offers));
	}

	function offers_homepage_baner(){
		$offers = array();
		$fields = array('id','lokalizacja','miasto','dzielnica','ulica','cena_od','powierzchnia_od','image','promocja','typ_name','transakcja_name');
		
		$offers = $this->Lex->get(array('conditions'=>array('ViewOffer.typ_id'=>array(0,1,2,3), 'ViewOffer.promocja'=>array(2,3)),'fields'=>$fields,'limit'=>10));
		if(empty($offers)) $offers = $this->Lex->get(array('conditions'=>array('ViewOffer.typ_id'=>array(0,1,2,3) ),'fields'=>$fields,'limit'=>10));
	
	
// 		debug($offers);
		return $this->View->element('main-baner',array('plugin'=>false,'offers'=>$offers));
	}
	
	function typy(){
		$types = $this->Lex->typy();
		return $types;
	}
	
	function transakcje(){
		$types = $this->Lex->transakcje();
		return $types;
	}	
}